home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 3.2 / Ham Radio Version 3.2 (Chestnut CD-ROMs)(1993).ISO / packet / n17jsrc / nrdump.c < prev    next >
C/C++ Source or Header  |  1991-02-05  |  3KB  |  117 lines

  1. /* NET/ROM header tracing routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "netrom.h"
  8. #include "nr4.h"
  9. #include "trace.h"
  10.  
  11. /* Display NET/ROM network and transport headers */
  12. void
  13. netrom_dump(fp,bpp,check)
  14. FILE *fp;
  15. struct mbuf **bpp;
  16. int check;
  17. {
  18.     char src[AXALEN],dest[AXALEN];
  19.     char tmp[AXBUF];
  20.     char thdr[NR4MINHDR];
  21.     register i;
  22.  
  23.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  24.         return;
  25.     /* See if it is a routing broadcast */
  26.     if(uchar(*(*bpp)->data) == NR3NODESIG) {
  27.         (void)PULLCHAR(bpp);        /* Signature */
  28.         pullup(bpp,tmp,ALEN);
  29.         tmp[ALEN] = '\0';
  30.         fprintf(fp,"NET/ROM Routing: %s\n",tmp);
  31.         for(i = 0;i < NRDESTPERPACK;i++) {
  32.             if (pullup(bpp,src,AXALEN) < AXALEN)
  33.                 break;
  34.             fprintf(fp,"        %12s",pax25(tmp,src));
  35.             pullup(bpp,tmp,ALEN);
  36.             tmp[ALEN] = '\0';
  37.             fprintf(fp,"%8s",tmp);
  38.             pullup(bpp,src,AXALEN);
  39.             fprintf(fp,"    %12s",pax25(tmp,src));
  40.             tmp[0] = PULLCHAR(bpp);
  41.             fprintf(fp,"    %3u\n",uchar(tmp[0]));
  42.         }
  43.         return;
  44.     }
  45.     /* Decode network layer */
  46.     pullup(bpp,src,AXALEN);
  47.     fprintf(fp,"NET/ROM: %s",pax25(tmp,src));
  48.  
  49.     pullup(bpp,dest,AXALEN);
  50.     fprintf(fp,"->%s",pax25(tmp,dest));
  51.  
  52.     i = PULLCHAR(bpp);
  53.     fprintf(fp," ttl %d\n",i);
  54.  
  55.     /* Read first five bytes of "transport" header */
  56.     pullup(bpp,thdr,NR4MINHDR);
  57.     switch(thdr[4] & NR4OPCODE){
  58.      case NR4OPPID:    /* network PID extension */
  59.         if (thdr[0] == NRPROTO_IP && thdr[1] == NRPROTO_IP) {
  60.              ip_dump(fp,bpp,check) ;
  61.             return;
  62.         }
  63.          else
  64.              fprintf(fp,"         protocol family %x, proto %x",
  65.              uchar(thdr[0]), uchar(thdr[1])) ;
  66.          break ;
  67.     case NR4OPCONRQ:    /* Connect request */
  68.         fprintf(fp,"         conn rqst: ckt %d/%d",uchar(thdr[0]),uchar(thdr[1]));
  69.         i = PULLCHAR(bpp);
  70.         fprintf(fp," wnd %d",i);
  71.         pullup(bpp,src,AXALEN);
  72.         fprintf(fp," %s",pax25(tmp,src));
  73.         pullup(bpp,dest,AXALEN);
  74.         fprintf(fp,"@%s",pax25(tmp,dest));
  75.         break;
  76.     case NR4OPCONAK:    /* Connect acknowledgement */
  77.         fprintf(fp,"         conn ack: ur ckt %d/%d my ckt %d/%d",
  78.          uchar(thdr[0]), uchar(thdr[1]), uchar(thdr[2]),
  79.          uchar(thdr[3]));
  80.         i = PULLCHAR(bpp);
  81.         fprintf(fp," wnd %d",i);
  82.         break;
  83.     case NR4OPDISRQ:    /* Disconnect request */
  84.         fprintf(fp,"         disc: ckt %d/%d",
  85.          uchar(thdr[0]),uchar(thdr[1]));
  86.         break;
  87.     case NR4OPDISAK:    /* Disconnect acknowledgement */
  88.         fprintf(fp,"         disc ack: ckt %d/%d",
  89.          uchar(thdr[0]),uchar(thdr[1]));
  90.         break;
  91.     case NR4OPINFO:    /* Information (data) */
  92.         fprintf(fp,"         info: ckt %d/%d",
  93.          uchar(thdr[0]),uchar(thdr[1]));
  94.         fprintf(fp," txseq %d rxseq %d",
  95.          uchar(thdr[2]), uchar(thdr[3]));
  96.         break;
  97.     case NR4OPACK:    /* Information acknowledgement */
  98.         fprintf(fp,"         info ack: ckt %d/%d",
  99.          uchar(thdr[0]),uchar(thdr[1]));
  100.         fprintf(fp," txseq %d rxseq %d",
  101.          uchar(thdr[2]), uchar(thdr[3]));
  102.         break;
  103.     default:
  104.          fprintf(fp,"         unknown transport type %d",
  105.          thdr[4] & 0x0f) ;
  106.         break;
  107.     }
  108.     if(thdr[4] & NR4CHOKE)
  109.         fprintf(fp," CHOKE");
  110.     if(thdr[4] & NR4NAK)
  111.         fprintf(fp," NAK");
  112.     if(thdr[4] & NR4MORE)
  113.         fprintf(fp," MORE");
  114.     putc('\n',fp);
  115. }
  116.  
  117.